package com.kefu.admin.modules.sys.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kefu.admin.modules.sys.model.Owner;
import com.kefu.admin.modules.sys.service.OwnerService;
import com.kefu.admin.modules.sys.vo.base.PageResultVo;
import com.kefu.admin.utils.ResultUtil;
import com.kefu.admin.modules.sys.vo.OwnerVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/sys/owner")
public class OwnerController {

    @Autowired
    private OwnerService ownerService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @PostMapping("/list")
    @ResponseBody
    public PageResultVo pageRoles(OwnerVo ownerVo) {
        try {
            PageHelper.startPage(ownerVo.getPageNum(),ownerVo.getPageSize());
            List<Owner> ownerList = ownerService.listOwner(ownerVo);
            PageInfo<Owner> pages = new PageInfo<>(ownerList);
            return ResultUtil.table(ownerList,pages.getTotal());
        } catch (Exception e) {
            logger.error(String.format("RoleController.loadRoles%s", e));
            throw e;
        }

    }

}
